<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <script type="text/javascript">
    // xhr2 - 请求超时设置
    var xhr = new XMLHttpRequest()
    // 设置超时时间
    xhr.timeout = 1000
    // 如果返回的结果超时，那么自动触发如下函数
    xhr.ontimeout = function () {
      console.log('请求超时')
    }
    xhr.open('get', 'http://www.liulongbin.top:3006/api/getbooks')
    xhr.send()
    xhr.onreadystatechange = function () {
      if (xhr.readyState === 4 && xhr.status === 200) {
        var ret = xhr.responseText
        console.log(ret)
      }
    }
  </script>
</body>
</html>